package com.baibei.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * {
 * "ordernum":"1234", #订单号
 * "name":"征服波尔多陈年XO", #商品名称
 * "area":"XPT", #产区
 * "last":12345, #最新价
 * "buyprice":1234, #买入价
 * "count":10, #数量
 * "buydirection":1, #订货类型 1：现价，2：结算价
 * "buyMoney":12344, #定金
 * "fee":12345, #订货服务费
 * "toplimit":30, #上升
 * "bottomlimit":20, #下降
 * "addtime":"12345678977655" #下单时间，时间戳
 * }
 * <p>
 * {
 * "orderid": 464,
 * "ordernum": "312300060117081617201995", #订单号
 * "wid": "6e6eaa634f304ffc81b5d320e87fa416123",
 * "ordertype": 3,
 * "buydirection": 2,
 * "productid": 2,
 * "buyprice": 166.16, #订货金额
 * "sellprice":156.11, #退订金额
 * "buymoney": 30, #订金
 * "fee": 0.6,
 * "count": 1,
 * "toplimit": 0.2,
 * "bottomlimit": 0.2,
 * "plamount": 1, #盈亏金额（订单差价）
 * "actualAmount":0.4, #实际差价
 * "addtime": "1502875195000", #订单时间
 * "selltime": null, #退订时间
 * "name": "征服波尔多经典XO", #商品名称
 * "area": "XPT",
 * "last": null,
 * "productpic": "http://crossboarder.oss-cn-shenzhen.aliyuncs.com/trade/product/020170808172050.jpg?x-oss-process=image/resize,m_mfit,h_100,w_100"
 * }
 * Created by shenminjie on 2017/8/9.
 * mail:shenminjie@100bei.com
 */

public class OrderInfo implements DateInfo, Parcelable, Serializable {

    /***************订货记录*************/

    private double actualAmount;

    private String wid;

    private int ordertype;

    private double sellprice;

//    private String buymoney;

    private double plamount;

    private long selltime;

    private double money;
    /***************订货记录*************/


    private String orderid;

    private String ordernum;

    private String name;

    private String productid;

    private String area;

    private String status; // 订单状态

    private double last;

    private double buyprice;

    private int count;

    /**
     * #订货类型 2：现价，1：结算价
     */
    private int buydirection;


    @SerializedName("buymoney")
    private double buyMoney;

    private double fee;

    private double toplimit;

    private double bottomlimit;

    private long addtime;

    private String productpic;

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getWid() {
        return wid;
    }

    public void setWid(String wid) {
        this.wid = wid;
    }

    public int getOrdertype() {
        return ordertype;
    }

    public void setOrdertype(int ordertype) {
        this.ordertype = ordertype;
    }

    public double getSellprice() {
        return sellprice;
    }

    public void setSellprice(double sellprice) {
        this.sellprice = sellprice;
    }

    public double getPlamount() {
        return plamount;
    }

    public void setPlamount(double plamount) {
        this.plamount = plamount;
    }

    public long getSelltime() {
        return selltime;
    }

    public void setSelltime(long selltime) {
        this.selltime = selltime;
    }

    public String getOrderid() {
        return orderid;
    }

    public void setOrderid(String orderid) {
        this.orderid = orderid;
    }

    public String getProductid() {
        return productid;
    }

    public void setProductid(String productid) {
        this.productid = productid;
    }

    public String getProductpic() {
        return productpic;
    }

    public void setProductpic(String productpic) {
        this.productpic = productpic;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public double getPrifitDifferent() {
        double price = (last - buyprice) * count;
        if (price == 0) {
            return 0;
        }
        return buydirection == BuyDirection.DIRECTION_CURRENT_PRICE ? price : -price;
    }

    /**
     * 获取涨跌百分比
     *
     * @return
     */
    public double getPrecent() {
        //float、double两种基本类型在运算的时候容易引起精度丢失
        BigDecimal x1 = new BigDecimal(last + "");
        BigDecimal x2 = new BigDecimal(buyprice + "");
        double price = x1.subtract(x2).doubleValue() * count;
        if (price == 0) {
            return 0;
        }
        return (buydirection == BuyDirection.DIRECTION_CURRENT_PRICE ? price / buyMoney : -price / buyMoney);
    }


    @Override
    public long getDate() {
        if (addtime == 0) {
            return System.currentTimeMillis();
        }
        return addtime;
    }

    public String getOrdernum() {
        return ordernum;
    }

    public void setOrdernum(String ordernum) {
        this.ordernum = ordernum;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public double getLast() {
        return last;
    }

    public void setLast(double last) {
        this.last = last;
    }

    public double getBuyprice() {
        return buyprice;
    }

    public void setBuyprice(double buyprice) {
        this.buyprice = buyprice;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getBuydirection() {
        return buydirection;
    }

    public void setBuydirection(int buydirection) {
        this.buydirection = buydirection;
    }

    public double getBuyMoney() {
        return buyMoney;
    }

    public void setBuyMoney(double buyMoney) {
        this.buyMoney = buyMoney;
    }

    public double getFee() {
        return fee;
    }

    public void setFee(double fee) {
        this.fee = fee;
    }

    public double getToplimit() {
        return toplimit;
    }

    public void setToplimit(double toplimit) {
        this.toplimit = toplimit;
    }

    public double getBottomlimit() {
        return bottomlimit;
    }

    public void setBottomlimit(double bottomlimit) {
        this.bottomlimit = bottomlimit;
    }

    public long getAddtime() {
        return addtime;
    }

    public void setAddtime(long addtime) {
        this.addtime = addtime;
    }

    public double getActualAmount() {
        return actualAmount;
    }

    public void setActualAmount(double actualAmount) {
        this.actualAmount = actualAmount;
    }

    @Override
    public String toString() {
        return "OrderInfo{" +
                "actualAmount=" + actualAmount +
                ", wid='" + wid + '\'' +
                ", ordertype=" + ordertype +
                ", sellprice='" + sellprice + '\'' +
                ", plamount='" + plamount + '\'' +
                ", selltime=" + selltime +
                ", money=" + money +
                ", orderid='" + orderid + '\'' +
                ", ordernum='" + ordernum + '\'' +
                ", name='" + name + '\'' +
                ", productid='" + productid + '\'' +
                ", area='" + area + '\'' +
                ", last=" + last +
                ", buyprice=" + buyprice +
                ", count=" + count +
                ", buydirection=" + buydirection +
                ", buyMoney=" + buyMoney +
                ", fee=" + fee +
                ", toplimit=" + toplimit +
                ", bottomlimit=" + bottomlimit +
                ", addtime=" + addtime +
                ", productpic='" + productpic + '\'' +
                '}';
    }

    public OrderInfo() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(this.actualAmount);
        dest.writeString(this.wid);
        dest.writeInt(this.ordertype);
        dest.writeDouble(this.sellprice);
        dest.writeDouble(this.plamount);
        dest.writeLong(this.selltime);
        dest.writeDouble(this.money);
        dest.writeString(this.orderid);
        dest.writeString(this.ordernum);
        dest.writeString(this.name);
        dest.writeString(this.productid);
        dest.writeString(this.area);
        dest.writeString(this.status);
        dest.writeDouble(this.last);
        dest.writeDouble(this.buyprice);
        dest.writeInt(this.count);
        dest.writeInt(this.buydirection);
        dest.writeDouble(this.buyMoney);
        dest.writeDouble(this.fee);
        dest.writeDouble(this.toplimit);
        dest.writeDouble(this.bottomlimit);
        dest.writeLong(this.addtime);
        dest.writeString(this.productpic);
    }

    protected OrderInfo(Parcel in) {
        this.actualAmount = in.readDouble();
        this.wid = in.readString();
        this.ordertype = in.readInt();
        this.sellprice = in.readDouble();
        this.plamount = in.readDouble();
        this.selltime = in.readLong();
        this.money = in.readDouble();
        this.orderid = in.readString();
        this.ordernum = in.readString();
        this.name = in.readString();
        this.productid = in.readString();
        this.area = in.readString();
        this.status = in.readString();
        this.last = in.readDouble();
        this.buyprice = in.readDouble();
        this.count = in.readInt();
        this.buydirection = in.readInt();
        this.buyMoney = in.readDouble();
        this.fee = in.readDouble();
        this.toplimit = in.readDouble();
        this.bottomlimit = in.readDouble();
        this.addtime = in.readLong();
        this.productpic = in.readString();
    }

    public static final Creator<OrderInfo> CREATOR = new Creator<OrderInfo>() {
        @Override
        public OrderInfo createFromParcel(Parcel source) {
            return new OrderInfo(source);
        }

        @Override
        public OrderInfo[] newArray(int size) {
            return new OrderInfo[size];
        }
    };
}
